package com.sphd.restaurantsystem.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

/**
 * Created by Hu on 2016/8/8.
 */
public abstract  class LazyLoadFragment extends BaseFragment {

    /**
     * 数据是否已加载完毕
     */
    private boolean isLoadDataCompleted;
    public abstract int getLayout();
    public abstract void initViews(View view);
    public abstract void loadData();
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser && isViewCreated && !isLoadDataCompleted) {
            loadData();
        }
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (getUserVisibleHint()) {
            loadData();
        }
    }
//    public void loadData() {
//        isLoadDataCompleted = true;
//    }

    public boolean isLoadDataCompleted() {
        return isLoadDataCompleted;
    }

    public void setLoadDataCompleted(boolean loadDataCompleted) {
        isLoadDataCompleted = loadDataCompleted;
    }



}
